/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.form.server.provider;

import java.util.List;

import com.genia.toolbox.basics.exception.BundledException;
import com.genia.toolbox.web.gwt.basics.client.oracle.SimpleSuggestion;
import com.genia.toolbox.web.gwt.form.client.form.Form;
import com.genia.toolbox.web.gwt.form.client.value.DataIdentifier;
import com.genia.toolbox.web.gwt.form.client.value.FormValues;

/**
 * this interface represents a Form and contains all the methods to handle
 * filling a form and saving one.
 */
public interface FormProvider
{

  /**
   * returns the identifier of the form handled by this object.
   * 
   * @return the identifier of the form handled by this object
   */
  public String getFormIdentifier();



  /**
   * returns the form handled by this object.
   * 
   * @param dataIdentifier
   *          the data identifier
   * @return the form handled by this object
   * @throws BundledException
   *           when an error occurred
   */
  public Form getForm(DataIdentifier dataIdentifier)
      throws BundledException;



  /**
   * retrieve the initial value of the object that is edited.
   * 
   * @param dataIdentifier
   *          the data identifier
   * @return the initial value of the object that is edited
   * @throws BundledException
   *           when an error occurred
   */
  public FormValues getInitialValue(DataIdentifier dataIdentifier)
      throws BundledException;



  /**
   * save the form on the server.
   * 
   * @param newValues
   *          the new values entered by the user
   * @return the new values that have been saved
   * @throws BundledException
   *           when an error occurred
   */
  public FormValues saveForm(FormValues newValues)
      throws BundledException;



  /**
   * get suggestions for a field.
   * 
   * @param dataIdentifier
   *          the data identifier
   * @param fieldName
   *          the field name
   * @param query
   *          the current value of the field
   * @param limit
   *          the maximum number of response
   * @return the list of suggestion for the field
   * @throws BundledException
   *           when an error occurred
   */
  public List<SimpleSuggestion> getSuggestions(DataIdentifier dataIdentifier, String fieldName, String query, int limit)
      throws BundledException;



  /**
   * get the display string for a given value.
   * 
   * @param fieldName
   *          the field name
   * @param value
   *          the current value of the field
   * @return the string to display for the given value
   * @throws BundledException
   *           when an error occurred
   */
  public String getDisplayString(String fieldName, String value)
      throws BundledException;

}
